package in.muton.edushare.pages.assignment;

import in.muton.edushare.auth.roles.CourseRoleCheck;
import in.muton.edushare.panels.assignment.AssigneeSubmissionPanel;
import in.muton.edushare.panels.assignment.SubmissionsProfView;

import org.apache.wicket.MarkupContainer;
import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.panel.Fragment;

import com.edushare.common.constants.ApplicationConstants;

public class Submissions extends AssignmentBase {

	private static final int USER_VISITOR = 1;
	private static final int USER_TEACHER = 2;
	private static final int USER_ASSIGNEE = 3;
	
	public Submissions(PageParameters params) {
		super(params);
		int userType = getPageVisitorType();
		if(userType == USER_ASSIGNEE){
			loadAssigneePanel();
		}else if(userType == USER_TEACHER){
			loadTeacherPanel();
		}else if(userType == USER_VISITOR){
			loadVisitorPanel();
		}
	}

	private void loadAssigneePanel() {
		add(new AssigneeSubmissionPanel("submissionsPanel", getModel()));
	}

	private void loadTeacherPanel() {
		add(new SubmissionsProfView("submissionsPanel", this, getModel()));
		
	}

	private void loadVisitorPanel() {
		add(new NotAllowedFrag("submissionsPanel", this));
	}

	private int getPageVisitorType() {
		CourseRoleCheck check = 
		new CourseRoleCheck(getModel().getObject().getCourseInstance(), getLoggedInUser());
		if(check.isStudent())
			return USER_ASSIGNEE;
		else if(check.isTeacher() || check.isAdmin())
			return USER_TEACHER;
		else
			return USER_VISITOR;
	}

	@Override
	protected String getActivePage() {
		return "assnSubmission";
	}

	@Override
	public String getPageTitle() {
		return "Assignment Submissions | "+getModel().getObject().getAssignmentTitle()+" | "+ ApplicationConstants.APPLICATION_NAME;
	}
	
	public class NotAllowedFrag extends Fragment{

		private static final long serialVersionUID = 6283754959315656246L;

		public NotAllowedFrag(String id, MarkupContainer container) {
			super(id, "notAllowedFrag", container);
		}
		
	}

}
